/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.editpart.connection;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.requests.DropRequest;

import com.cea.papyrus.diagraminterchange2.di2.GraphConnector;

/**
 * Associates an anchor to a request or to a ConnectionEditPart.
 */
public class EllipseAnchorMngr extends AnchorMngr /* implements NodeEditPart */
{

	/**
	 * 
	 * 
	 * @param editPart 
	 */
	public EllipseAnchorMngr(AnchorableGraphNodeEditPart editPart) {
		super(editPart);
	}

	/**
	 * Create an anchor for the specified request.
	 * 
	 * @param request 
	 * 
	 * @return ConnectionAnchor
	 */
	public ConnectionAnchor createAnchor(Request request) {
		Point pt = new Point(((DropRequest) request).getLocation());
		return new BoxBorderRequestAnchor(getHost().getFigure(), pt);
	}

	/**
	 * Create anchor for the specified ConnectionEditPart.
	 * 
	 * @param connection 
	 * @param connector 
	 * 
	 * @return ConnectionAnchor
	 */
	public ConnectionAnchor createAnchor(ConnectionEditPart connection, GraphConnector connector) {
		return new BoxBorderAnchor(getHost().getFigure(), connector);
//		return new EllipseAnchor(getHost().getFigure());

	}

	/**
	 * Compute the anchor position for the specified position point.
	 * For a rectangle, compute the intersection between the line made by center, reference and the border.
	 * Return a new Point. The provided parameter is not modified.
	 * 
	 * @param box 
	 * @param reference The position used to compute the anchor..
	 * 
	 * @return 
	 */
	public Point getAnchorPosition(Point reference, Rectangle box) {
		return getEllipseIntersect(reference, box);
	}
}
